# -*- coding: utf-8 -*-
# @Time : 2018/12/24 18:58
# @Author : Administrator
# @File : TestCase.py
# @Project : 4.Python
# @title : woniusales_testcase
import http.client
# from WoniuSales_httpTest import utility
from API_test.WoniuSales_httpTest.utility import Utility


class Testcase():
    #登录
    def login_test(self,username,password,verifycode,expect):
        con=http.client.HTTPConnection(host='192.168.2.159',port=8080)
        con.request(method='POST',url='/woniusales/user/login',
                    body='username='+username+'&password='+password+'&verifycode='+verifycode,
                    headers={'Content-Type':'application/x-www-form-urlencoded'})
        # print(con.getresponse().read().decode())
        actural=con.getresponse().read().decode()
        #断言登录结果是否符合预期
        if actural == expect:
            print('login_test succeed.')
        else:
            print('logint_test failed.')
        con.close()
    #新增会员
    def addMember_test(self,name,phone,sex,date,creditkids,creditcloth,expect):
        # 获取cookie
        con = http.client.HTTPConnection(host='192.168.2.159', port=8080)
        con.request(method='POST', url='/woniusales/user/login',
                    body='username=admin&password=admin&verifycode=0000',
                    headers={'Content-Type': 'application/x-www-form-urlencoded'})
        cookies=con.getresponse().getheader(name='Set-Cookie')
        cookie1=cookies.split(';')[0]
        # print(cookie1)
        con.close()
        #新增会员
        con = http.client.HTTPConnection(host='192.168.2.159', port=8080)
        con.request(method='POST', url='/woniusales/customer/add',
                    body='customername='+name+'&customerphone='+phone+'&childsex='+sex+'&childdate='+date+'&creditkids='+creditkids+'&creditcloth='+creditcloth,
                    headers={"Content-Type": "application/x-www-form-urlencoded","Cookie":cookie1})
        actural = con.getresponse().read().decode()
        print(actural)
        #断言新增会员的结果是否符合预期
        # if actural== expect:
        #     print('addMember succeed.')
        # else:
        #     print('addMember failed.')
        con.close()
if __name__ == '__main__':
    t=Testcase()
    # t.login_test('admin','admin','0000','login-pass')
    # t.addMember_test('Lice','187123422234','1','','100','200','add-successful')

